package com.starsoft.frame.fileimport.pojo;


public class Column {

	public static final String codePrix = "Col_";

	private Integer colIndex;
	private String code;
	private String mapKey;
	private String name;
	private ValueType valueType;
	private NullType nullType;
	private Object defaultValue;
	private String format;

	public Column(int colIndex) {
		this.colIndex = colIndex;
		code = codePrix + colIndex;
		mapKey = code;
		name = code;
	}
	
	public Column(Integer colIndex, String mapkey, ValueType valueType, NullType nullType) {
		this(colIndex, mapkey, valueType, nullType, null);
	}
	
	public Column(Integer colIndex, String mapkey, ValueType valueType, NullType nullType, String format) {
		this.colIndex = colIndex;
		this.code = codePrix + colIndex;
		this.name = codePrix + colIndex;
		this.mapKey = mapkey;
		this.valueType = valueType;
		this.nullType = nullType;
		this.format = format;
	}
	
	public Column(Integer colIndex, String code, String name, ValueType valueType, NullType nullType,
			Object defaultValue) {
		if (code == null && name == null) {
			code = codePrix + colIndex;
			name = code;
		} else if (name == null) {
			name = code;
		} else if (code == null) {
			code = name;
		}
		this.colIndex = colIndex;
		this.code = code;
		this.mapKey = code;
		this.name = name;
		this.valueType = valueType;
		this.nullType = nullType;
		this.defaultValue = defaultValue;
	}
	
	public Column(String code, ValueType valueType, NullType nullType) {
		this(code, code, valueType, nullType, null);
	}
	
	public Column(String code, String mapkey, ValueType valueType, NullType nullType) {
		this(code, mapkey, valueType, nullType, null);
	}
	
	public Column(String code, String mapkey, ValueType valueType, NullType nullType, String format) {
		if (code == null) {
			throw new RuntimeException("code is null");
		}
		this.code = code;
		this.name = code;
		this.mapKey = mapkey;
		this.valueType = valueType;
		this.nullType = nullType;
		this.format = format;
	}

	public void updateIf(Integer colIndex, String code, String name, ValueType valueType, NullType nullType,
			Object defaultValue){
		if(colIndex!=null){
			this.colIndex=colIndex;
		}
		if(code!=null){
			this.code=code;
		}
		if(name!=null){
			this.name=name;
		}
		if(valueType!=null){
			this.valueType=valueType;
		}
		if(nullType!=null){
			this.nullType=nullType;
		}
		if(defaultValue!=null){
			this.defaultValue=defaultValue;
		}
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMapKey() {
		return mapKey;
	}

	public void setMapKey(String mapKey) {
		this.mapKey = mapKey;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public ValueType getValueType() {
		if(valueType==null){
			return ValueType.String;
		}
		return valueType;
	}

	public void setValueType(ValueType valueType) {
		this.valueType = valueType;
	}

	public NullType getNullType() {
		if(nullType==null){
			return NullType.nullable;
		}
		return nullType;
	}

	public void setNullType(NullType nullType) {
		this.nullType = nullType;
	}

	public Object getDefaultValue() {
		return defaultValue;
	}

	public void setDefaultValue(Object defaultValue) {
		this.defaultValue = defaultValue;
	}

	public Integer getColIndex() {
		return colIndex;
	}

	public void setColIndex(Integer colIndex) {
		this.colIndex = colIndex;
	}

	public String getFormat() {
		return format;
	}

	public void setFormat(String format) {
		this.format = format;
	}

}
